using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using JTLeigh.Tools.Development.CopySourceAsHtml.Properties;

namespace JTLeigh.Tools.Development.CopySourceAsHtml.UnitTests
{

    /// <summary>
    /// Unit tests for the <see cref="Copier"/> class.
    /// </summary>
    [TestClass]
    public class CopierFixture
    {
        #region Methods

		#region CreateFileStyle

		/// <summary>
		/// Ensures <see cref="Copier.CreateFileStyle"/> correctly throws <see cref="ArgumentNullException"/>
		/// when called with a <see langword="null"/> font list.
		/// </summary>
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TestCreateFileStyleWithNullFontList()
		{
			Copier.CreateFileStyle(null, 10, new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false), "border-width: thin;");
		}

		/// <summary>
		/// Ensures <see cref="Copier.CreateFileStyle"/> correctly throws <see cref="ArgumentNullException"/>
		/// when called with a <see langword="null"/> plain text style.
		/// </summary>
		[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "PlainText")]
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TestCreateFileStyleWithNullPlainTextStyle()
		{
			Copier.CreateFileStyle("Courier New", 10, null, "border-width: thin;");
		}

		/// <summary>
		/// Ensures <see cref="Copier.CreateFileStyle"/> creates a style containing only the 
		/// font family, font size, and plain text style when passed a <see langword="null"/> file
		/// style overrides value.
		/// </summary>
		[TestMethod]
		public void TestCreateFileStyleWithNullFileStyleOverrides()
		{
			ColorableItemStyle plainTextStyle;
			HtmlStyle fileStyle;

			plainTextStyle = new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false);
			fileStyle = Copier.CreateFileStyle("Courier New", 10, plainTextStyle, null);
			Assert.AreEqual("color: black; background: white; font-family: Courier New; font-size: 10pt;", fileStyle.ToString());
		}

		/// <summary>
		/// Ensures <see cref="Copier.CreateFileStyle"/> creates a style containing the font
		/// family, font size, plain text style, and file style overrides.
		/// </summary>
		[TestMethod]
		public void TestCreateFileStyle()
		{
			ColorableItemStyle plainTextStyle;
			HtmlStyle fileStyle;

			plainTextStyle = new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false);
			fileStyle = Copier.CreateFileStyle("Courier New", 10, plainTextStyle, "border-width: thin;");
			Assert.AreEqual("color: black; background: white; font-family: Courier New; font-size: 10pt; border-width: thin;", fileStyle.ToString());
		}

		#endregion // CreateFileStyle

		#region CreateLineStyle

		/// <summary>
		/// Ensures <see cref="Copier.CreateLineStyle"/> creates a style containing only the 
		/// margin when passed a <see langword="null"/> line style overrides value.
		/// </summary>
		[TestMethod]
		public void TestCreateLineStyleWithNullLineStyleOverrides()
		{
			ColorableItemStyle plainTextStyle;
			HtmlStyle lineStyle;

			plainTextStyle = new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false);
			lineStyle = Copier.CreateLineStyle(plainTextStyle, null);
			Assert.AreEqual("margin: 0px;", lineStyle.ToString());
		}

		/// <summary>
		/// Ensures <see cref="Copier.CreateLineStyle"/> creates a style containing the margin
		/// and line style overrides.
		/// </summary>
		[TestMethod]
		public void TestCreateLineStyle()
		{
			ColorableItemStyle plainTextStyle;
			HtmlStyle lineStyle;

			plainTextStyle = new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false);
			lineStyle = Copier.CreateLineStyle(plainTextStyle, "height: 50px;");
			Assert.AreEqual("margin: 0px; height: 50px;", lineStyle.ToString());
		}

		#endregion // CreateLineStyle

        #region Constructors

		/// <summary>
		/// Ensures the <see cref="Copier"/> constructor correctly throws <see cref="ArgumentNullException"/>
		/// when called with a <see langword="null"/> settings value.
		/// </summary>
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TestConstructorWithNullSettings()
		{
			ColorableItemStyle plainTextStyle;
			ColorableItemStyle lineNumberStyle;

			plainTextStyle = new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false);
			lineNumberStyle = new ColorableItemStyle(new HtmlColor(0, 128, 0), new HtmlColor(255, 255, 255), false);
			new Copier(null, plainTextStyle, lineNumberStyle);
		}

		/// <summary>
		/// Ensures the <see cref="Copier"/> constructor correctly throws <see cref="ArgumentNullException"/>
		/// when called with a <see langword="null"/> plain text style.
		/// </summary>
		[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "PlainText")]
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TestConstructorWithNullPlainTextStyle()
		{
			Settings settings;
			ColorableItemStyle lineNumberStyle;

			settings = new Settings();
			lineNumberStyle = new ColorableItemStyle(new HtmlColor(0, 128, 0), new HtmlColor(255, 255, 255), false);
			new Copier(settings, null, lineNumberStyle);
		}

		/// <summary>
		/// Ensures the <see cref="Copier"/> constructor correctly throws <see cref="ArgumentNullException"/>
		/// when called with a <see langword="null"/> line number style.
		/// </summary>
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TestConstructorWithNullLineNumberStyle()
		{
			Settings settings;
			ColorableItemStyle plainTextStyle;

			settings = new Settings();
			plainTextStyle = new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false);
			new Copier(settings, plainTextStyle, null);
		}

		#endregion // Constructors

        #region CopyAsHtml

        /// <summary>
        /// Ensures <see cref="Copier.CopyAsHtml"/> correctly throws <see cref="ArgumentNullException"/>
        /// when called with a <see langword="null"/> RTF value.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestCopyAsHtmlWithNullRtf()
        {
            Settings settings;
            ColorableItemStyle plainTextStyle;
            ColorableItemStyle lineNumberStyle;
            Copier copier;

            settings = new Settings();
            plainTextStyle = new ColorableItemStyle(new HtmlColor(0, 0, 0), new HtmlColor(255, 255, 255), false);
            lineNumberStyle = new ColorableItemStyle(new HtmlColor(0, 128, 0), new HtmlColor(255, 255, 255), false);
            copier = new Copier(settings, plainTextStyle, lineNumberStyle);

            copier.CopyAsHtml(@"C:\Projects\CopySourceAsHtml\Test.cs", null);
        }

        #endregion // CopyAsHtml

        #endregion // Methods
    }

}
